/********************************************
*Author: Lisandro Martinez					*
*Description:	SDL graphics engine			*
*Date: 8-30-2012							*
*********************************************/
#ifdef _WIN32
#include "SDL.h"
#include "SDL_image.h"
#include "SDL_ttf.h"
#else
#include "SDL/SDL.h"
#include "SDL/SDL_image.h"
#include "SDL/SDL_ttf.h"
#endif
#include <string>

#ifndef _SDL_GraphicsEngine_
#define  _SDL_GraphicsEngine_

class SDL_GraphicsEngine
{


public:
	static const int SCREEN_WIDTH = 640;
	static const int SCREEN_HEIGHT = 480;
	static const int SCREEN_BPP = 32;
	bool init(char* wincaption);
	void clean_up();
private:
	static SDL_Surface *screen;
	SDL_GraphicsEngine(void);
	////////////////////////////////////////////////////////////////////////
	//
	// FUNCTION:    SDL_GraphicsEngine()
	//
	// DESCRIPTION: The private 	Copy Constructor
	//
	////////////////////////////////////////////////////////////////////////
	SDL_GraphicsEngine( const SDL_GraphicsEngine &){}

	////////////////////////////////////////////////////////////////////////
	//
	// FUNCTION:    operator=()
	//
	// DESCRIPTION: The private Assignment Operator
	//
	////////////////////////////////////////////////////////////////////////
	SDL_GraphicsEngine &operator = (const SDL_GraphicsEngine &){}

	////////////////PROPERTIES/////////////////////////
	static SDL_GraphicsEngine *pInstance;//Instantiate the instance of the main class
public:

	////////////////////////////////////////////////////////////////////////
	//
	// FUNCTION:    GetInstance()
	//
	// DESCRIPTION: Access the only instance of the class.
	//
	////////////////////////////////////////////////////////////////////////
	static SDL_GraphicsEngine *GetInstance(void);
	////////////////////////////////////////////////////////////////////////
	//
	// FUNCTION:    DeleteInstancce()
	//
	// DESCRIPTION: Delete the only instance of the class.
	//
	////////////////////////////////////////////////////////////////////////
	static void DeleteInstancce(void);
	////////////////////////////////////////////////////////////////////////
	//
	// FUNCTION:    ~SDL_GraphicsEngine()
	//
	// DESCRIPTION: The SDL_GraphicsEngine class distructor.
	//
	////////////////////////////////////////////////////////////////////////
	~SDL_GraphicsEngine(void);

	bool Update()
	{
		//Update the screen
		if( SDL_Flip( screen ) == -1 )
		{
		    return false;
		}
		return true;
	}

	SDL_Surface *Load(std::string name)
	{
		return load_image(name);

	}
	TTF_Font *Load(std::string name, int size)
	{

		return TTF_OpenFont( name._Myptr(), size );

	}
	void Draw(SDL_Surface *surface,int x, int y,SDL_Rect* clip = NULL)
	{
		apply_surface(x,y,surface,screen,clip);
	}
private:
	SDL_Surface *load_image( std::string filename );
	void apply_surface( int x, int y, SDL_Surface* source, SDL_Surface* destination, SDL_Rect* clip = NULL );

};
#endif

